home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Text Editor / Source / TextEditor.cpp < prev    next >
Encoding:
Text File  |  1995-12-13  |  10.1 KB  |  547 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2.  
  3.     File:            TextEditor.cpp
  4.     
  5.     Written by:        Steve Smith
  6.     
  7.     Copyright:        © 1995 by Apple Computer, Inc., all rights reserved.
  8.     
  9.     Description:    TextEditor demonstrates a fully functional embedding
  10.                     styled text editor. etc....
  11.                     
  12.                     The implementation is divided into protocols with
  13.                     one file per protocol. This will hopefully make it
  14.                     easier to get around.
  15.     
  16.     
  17.     Demonstrates:    The following recipes were used in implementing the
  18.                     TextEditor:
  19.                      1. Open
  20.                      2. Adding A Display Frame
  21.                      3. Adding A Facet
  22.                      4. Part Drawing
  23.                      5. Refcounting Geometry
  24.                      6. ViewTypes & Presentations
  25.                      7. Display Frame 'ternalization
  26.                      8. Part Init & Externalization
  27.                      9. Part Init & partWrapper
  28.                     10. Part Storage Model
  29.                     11. Persistent Reference
  30.                     12. RefCounting
  31.                     13. Storage Unit
  32.                     14. Activation
  33.                     15. Basic Event Handling
  34.                     16. Menus
  35.                     17. Windows & Dialogs
  36.                     18. Exception Handling
  37.                     19. Memory Manager
  38.                     20. Using Resources
  39.     
  40.     
  41.     Notes:            • The SOM_CATCH macro acts as an umbrella exception
  42.                     "catcher" for the entire method. If at any point an
  43.                     exception is thrown, the exception value (Error Code) is
  44.                     stuffed into the 'ev' parameter passed into the method and
  45.                     the code following the macro is executed. 
  46.     
  47.                     • For methods where it is necessary to call the parent class
  48.                     implementation, the calls are made from the SOM class. See
  49.                     som_SamplePart.cpp and the Class Reference to know whether
  50.                     you need to call the parent class from any method.
  51.                     
  52.     
  53.     Known Problems:    <none>
  54.     
  55. ------------------------------------------------------------------------------*/
  56.  
  57.  
  58. // -- Compiler/Preprocessor Notification --
  59.  
  60. // Notification that this is a SOM source file
  61. #define SampleCode_TextEditor_Class_Source
  62. // define underscore (_) field names
  63. #define VARIABLE_MACROS
  64.  
  65. #ifndef _COMPILERDEFS_
  66. #include "CompDefs.h"
  67. #endif
  68.  
  69. // -- OpenDoc Utilities --
  70.  
  71. #ifndef _EXCEPT_
  72. #include "Except.h"
  73. #endif
  74.  
  75. // -- TextEditor Includes
  76.  
  77. #ifndef _TEXTEDITORGLOBALS_
  78. #include "TextEditorGlobals.h"
  79. #endif
  80.  
  81. #ifndef SOM_SampleCode_TextEditor_xih
  82. #include "TextEditor.xih"
  83. #endif
  84.  
  85. #ifndef _TEXTEDITORDEF_
  86. #include "TextEditorDef.h"
  87. #endif
  88.  
  89. #ifndef _TEXTEDITORUTILS_
  90. #include "TextEditorUtils.h"
  91. #endif
  92.  
  93. #ifndef _VALUESTREAM_
  94. #include "ValueStream.h"
  95. #endif
  96.  
  97. #ifndef _PARTRUN_
  98. #include "PartRun.h"
  99. #endif
  100.  
  101. #ifndef _STDTEXTPROPERTIES_
  102. #include "StdTextProps.h"
  103. #endif
  104.  
  105. #ifndef _TEXTEDITORPREFS_
  106. #include "TextEditorPrefs.h"
  107. #endif
  108.  
  109. #ifndef _TEXTEDITORSETTINGS_
  110. #include "TextEditorSettings.h"
  111. #endif
  112.  
  113. // -- OpenDoc Includes --
  114.  
  115. #ifndef _ODTYPES_
  116. #include <ODTypes.h>
  117. #endif
  118.  
  119. #ifndef SOM_ODPart_xh
  120. #include <Part.xh>
  121. #endif
  122.  
  123. #ifndef SOM_ODSemanticInterface_xh
  124. #include <SemtIntB.xh>
  125. #endif
  126.  
  127. #ifndef SOM_ODFacet_xh
  128. #include <Facet.xh>
  129. #endif
  130.  
  131. #ifndef SOM_ODFrame_xh
  132. #include <Frame.xh>
  133. #endif
  134.  
  135. #ifndef SOM_ODFrameFacetIterator_xh
  136. #include <FrFaItr.xh>
  137. #endif
  138.  
  139. #ifndef SOM_ODArbitrator_xh
  140. #include <Arbitrat.xh>
  141. #endif
  142.  
  143. #ifndef SOM_ODDispatcher_xh
  144. #include <Disptch.xh>
  145. #endif
  146.  
  147. #ifndef SOM_Module_OpenDoc_Foci_defined
  148. #include <Foci.xh>
  149. #endif
  150.  
  151. #ifndef SOM_ODShape_xh
  152. #include <Shape.xh>
  153. #endif
  154.  
  155. #ifndef SOM_Module_OpenDoc_StdProps_defined
  156. #include <StdProps.xh>
  157. #endif
  158.  
  159. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  160. #include <StdTypes.xh>
  161. #endif
  162.  
  163. #ifndef _STDDEFS_
  164. #include <StdDefs.h>
  165. #endif
  166.  
  167. #ifndef SOM_Module_OpenDoc_Commands_defined
  168. #include <CmdDefs.xh>
  169. #endif
  170.  
  171. #ifndef SOM_ODDraft_xh
  172. #include <Draft.xh>
  173. #endif
  174.  
  175. #ifndef SOM_ODClipboard_xh
  176. #include <Clipbd.xh>
  177. #endif
  178.  
  179. #ifndef SOM_ODTranslation_xh
  180. #include "Translt.xh"
  181. #endif
  182.  
  183. #ifndef SOM_ODStorageUnit_xh
  184. #include <StorageU.xh>
  185. #endif
  186.  
  187. #ifndef SOM_ODStorageUnitView_xh
  188. #include <SUView.xh>
  189. #endif
  190.  
  191. #ifndef SOM_ODDragAndDrop_xh
  192. #include <DragDrp.xh>
  193. #endif
  194.  
  195. #ifndef SOM_ODDragItemIterator_xh
  196. #include <DgItmIt.xh>
  197. #endif
  198.  
  199. #ifndef SOM_ODTransform_xh
  200. #include <Trnsform.xh>
  201. #endif
  202.  
  203. #ifndef SOM_ODFocusSet_xh
  204. #include <FocusSet.xh>
  205. #endif
  206.  
  207. #ifndef SOM_ODMenuBar_xh
  208. #include <MenuBar.xh>
  209. #endif
  210.  
  211. #ifndef SOM_ODWindow_xh
  212. #include <Window.xh>
  213. #endif
  214.  
  215. #ifndef SOM_ODWindowState_xh
  216. #include <WinStat.xh>
  217. #endif
  218.  
  219. #ifndef SOM_ODCanvas_xh
  220. #include <Canvas.xh>
  221. #endif
  222.  
  223. #ifndef SOM_ODSession_xh
  224. #include <ODSessn.xh>
  225. #endif
  226.  
  227. #ifndef SOM_ODSemanticInterface_xh
  228. #include <SemtIntf.xh>
  229. #endif
  230.  
  231. #ifndef SOM_ODTypeList_xh
  232. #include <TypeList.xh>
  233. #endif
  234.  
  235. #ifndef SOM_ODTypeListIterator_xh
  236. #include <TypLsItr.xh>
  237. #endif
  238.  
  239.  
  240. // -- OpenDoc Utilities --
  241.  
  242. #ifndef _ODDEBUG_
  243. #include <ODDebug.h>
  244. #endif
  245.  
  246. #ifndef _ALTPOINT_
  247. #include <AltPoint.h>
  248. #endif
  249.  
  250. #ifndef _BARRAY_
  251. #include <BArray.h>
  252. #endif
  253.  
  254. #ifndef _ODMEMORY_
  255. #include <ODMemory.h>
  256. #endif
  257.  
  258. #ifndef _USERSRCM_
  259. #include <UseRsrcM.h>
  260. #endif
  261.  
  262. #ifndef _FOCUSLIB_
  263. #include <FocusLib.h>
  264. #endif
  265.  
  266. #ifndef _ISOSTR_
  267. #include <ISOStr.h>
  268. #endif
  269.  
  270. #ifndef _POUTILS_
  271. #include <POUtils.h>
  272. #endif
  273.  
  274. // -- Macintosh Includes --
  275.  
  276. #ifndef __ERRORS__
  277. #include <Errors.h>
  278. #endif
  279.  
  280. #ifndef __EVENTS__
  281. #include <Events.h>
  282. #endif
  283.  
  284. #ifndef __DRAG__
  285. #include <Drag.h>
  286. #endif
  287.  
  288. #ifndef __RESOURCES__
  289. #include <Resources.h>
  290. #endif
  291.  
  292. #ifndef __DIALOGS__
  293. #include <Dialogs.h>
  294. #endif
  295.  
  296. #ifndef __CONTROLS__
  297. #include <Controls.h>
  298. #endif
  299.  
  300. #ifndef __FONTS__
  301. #include <Fonts.h>
  302. #endif
  303.  
  304. #ifndef __TOOLUTILS__
  305. #include <ToolUtils.h>
  306. #endif
  307.  
  308. #ifndef __ICONS__
  309. #include <Icons.h>
  310. #endif
  311.  
  312. #ifndef __QUICKDRAW__
  313. #include <Quickdraw.h>
  314. #endif
  315.  
  316. #ifndef __PRINTING__
  317. #include <Printing.h>
  318. #endif
  319.  
  320. #ifndef __LOWMEM__
  321. #include <LowMem.h>
  322. #endif
  323.  
  324. #ifndef mathRoutinesIncludes
  325. #include <math routines.h>
  326. #endif
  327.  
  328. // -- Textension Includes --
  329.  
  330. #ifndef _Textension_
  331. #include "Textension.h"
  332. #endif
  333.  
  334. #ifndef _QDTextRun_
  335. #include "QDTextRun.h"
  336. #endif
  337.  
  338. #ifndef _AdvancedRuler_
  339. #include "AdvancedRuler.h"
  340. #endif
  341.  
  342. #ifndef _RunObject_
  343. #include "RunObject.h"
  344. #endif
  345.  
  346. #ifndef _LinkedFrames_
  347. #include "LinkedFrames.h"
  348. #endif
  349.  
  350. #ifndef _AttrObject_
  351. #include "AttrObject.h"
  352. #endif
  353.  
  354. #ifndef _FileStream_
  355. #include "FileStream.h"
  356. #endif
  357.  
  358. //#ifndef _RulerUI_
  359. //#include "RulerUI.h"
  360. //#endif
  361.  
  362.  
  363. #include "TextEditorInitialize.cpp"
  364. //==============================================//
  365. // Protocol:    Initialization                    
  366. //                                                
  367. // Methods:        Constructor                        
  368. //                Destructor                        
  369. //                InitPart                            
  370. //                InitPartFromStorage                
  371. //                Initialize                        
  372. //                StartTextension                    
  373. //                InitializeTextension            
  374. //                LoadMenus                        
  375. //==============================================//
  376.  
  377. #include "TextEditorStorage.cpp"
  378. //==============================================//
  379. // Protocol:    Storage
  380. //
  381. // Methods:        Release
  382. //                ReleaseAll
  383. //                Purge
  384. //                InternalizeStateInfo
  385. //                InternalizeContent
  386. //                Externalize
  387. //                ExternalizeStateInfo
  388. //                ExternalizeContent
  389. //                CleanseContentProperty
  390. //                CheckAndAddProperties
  391. //                SetDirty
  392. //                ReadPartInfo
  393. //                WritePartInfo
  394. //                ClonePartInfo
  395. //                SUHasValidData
  396. //                StreamDataOut
  397. //                StreamDataIn
  398. //                ExternalizeKinds
  399. //                ChangeKind
  400. //==============================================//
  401.  
  402. #include "TextEditorLayout.cpp"
  403. //==============================================//
  404. // Protocol:    Layout
  405. //
  406. // Methods:        DisplayFrameAdded
  407. //                DisplayFrameConnected
  408. //                DisplayFrameRemoved
  409. //                DisplayFrameClosed
  410. //                AttachSourceFrame
  411. //                ViewTypeChanged
  412. //                CalcNewUsedShape
  413. //                UpdateFrame
  414. //                FrameShapeChanged
  415. //                Open
  416. //                GetFramesWindow
  417. //                CreateWindow
  418. //                GetDefaultWindowProperties
  419. //                GetSavedWindowProperties
  420. //                CalcPartWindowSize
  421. //                CalcPartWindowPosition
  422. //                GetActiveFacetForFrame
  423. //                SequenceChanged
  424. //                RequestEmbeddedFrame
  425. //                RemoveEmbeddedFrame
  426. //                RequestFrameShape
  427. //                UsedShapeChanged
  428. //                AdjustBorderShape
  429. //==============================================//
  430.  
  431. #include "TextEditorImaging.cpp"
  432. //==============================================//
  433. // Protocol:    Imaging
  434. //
  435. // Methods:        GenerateThumbnail
  436. //                FacetAdded
  437. //                FacetRemoved
  438. //                Draw
  439. //                DrawFrameView
  440. //                DrawPageBounds
  441. //                DrawIconView
  442. //                DrawThumbnailView
  443. //                GeometryChanged
  444. //                HilightChanged
  445. //                CalcViewRect
  446. //                CalcTextBounds
  447. //                AdjustScrollbars
  448. //                CalcSelectionRgn
  449. //                PresentationChanged
  450. //                RepositionScrollbars
  451. //                CanvasChanged
  452. //                CanvasUpdated
  453. //                GetPrintResolution
  454. //==============================================//
  455.  
  456. #include "TextEditorActivation.cpp"
  457. //==============================================//
  458. // Protocol:    Activation
  459. //
  460. // Methods:        BeginRelinquishFocus
  461. //                CommitRelinquishFocus
  462. //                AbortRelinquishFocus
  463. //                FocusAcquired
  464. //                FocusLost
  465. //                ActivateFrame
  466. //                ActivateTextension
  467. //                ActivateScrollbars
  468. //                WindowActivating
  469. //==============================================//
  470.  
  471. //#include "TextEditorEvents.cpp"
  472. //==============================================//
  473. // Protocol:    Event Handling
  474. //
  475. // Methods:        AdjustMenus
  476. //                AdjustEditMenu
  477. //                AdjustTextEditorMenus
  478. //                SetMenuItem
  479. //                AdjustDynamicMenuItems
  480. //                HandleEvent
  481. //                HandleMenuEvent
  482. //                HandleWindowEvent
  483. //                HandleKeyboardEvent
  484. //                HandleMouseEvent
  485. //                MouseEnter
  486. //                MouseWithin
  487. //                MouseLeave
  488. //                DragEnter
  489. //                DragWithin
  490. //                DragLeave
  491. //                Drop
  492. //                UndoAction
  493. //                RedoAction
  494. //                DisposeActionState
  495. //                ReadActionState
  496. //                WriteActionState
  497. //                DoMouseEvent
  498. //                DoScrollDocument
  499. //                DoDragSelection
  500. //                DoCut
  501. //                DoCopy
  502. //                DoPaste
  503. //                DoPasteAs
  504. //                DoClear
  505. //                DoSelectAll
  506. //                DoOpenSelection
  507. //                DoInsert
  508. //                DoPageSetup
  509. //                DoPrint
  510. //                DoUndo
  511. //                DoPartInfo
  512. //                DoPreferences
  513. //                ShowHideRuler
  514. //                DoSettings
  515. //                RealFontSizeMenu
  516. //                DoTextStyling
  517. //                DoOtherFontSize
  518. //                DoIdle
  519. //                DoAboutBox
  520. //==============================================//
  521.  
  522. #include "TextEditorEmbedding.cpp"
  523. //==============================================//
  524. // Protocol:    Embedding
  525. //
  526. // Methods:        EmbedForeignContent
  527. //                AddEmbeddedFacet
  528. //                CreateEmbeddedRunObject
  529. //                ContainingPartPropertiesChanged
  530. //                GetContainingPartProperties
  531. //                RevealFrame
  532. //                EmbeddedFrameSpec
  533. //                CreateEmbeddedFramesIterator
  534. //==============================================//
  535.  
  536. #include "TextEditorLinking.cpp"
  537. //==============================================//
  538. // Protocol:    Linking
  539. //
  540. // Methods:        CreateLink
  541. //                LinkUpdated
  542. //                RevealLink
  543. //                EmbeddedFrameChanged
  544. //                LinkStatusChanged
  545. //
  546. //==============================================//
  547.